'''

'''
import requests
import hashlib

# # 案例1：
# # 构造 url
# url = r'https://www.httpbin.org/post'
# # 构造 files
# files = {'file':open(r'1.txt',mode='rb')}
# # 发送请求
# resp = requests.post(url,files=files,verify=False)
# print(resp.text)

# # 案例2：百度通过图片进行搜索
# # 构造 url
# url = r'https://graph.baidu.com/upload'
# # 构造 files
# files = {
#     'image': ('caomei.png', open(r'caomei.png', mode='rb'), 'image/png'),
#     'tn': 'pc',
#     'from': 'pc',
#     'image_source': 'PC_UPLOAD_SEARCH_FILE',
#     'range': '{"page_from": "searchIndex"}',
#     'sdkParams': '{"data":"4bba7cbbdbb3a718ba0a4561c27d3d3e568cc094461e4a86d8fae204ed46781e4dd561ce5897bc032a412e85656b5417eef41825aeac18e3147307b3f6fec3f562c601e50846f7b3002826b79eb1e059","key_id":"23","sign":"df49d9b6"}'
# }
# resp = requests.post(url, files=files, verify=False)
# print(resp.text)

# 案例3：
# ----------------------登录----------------------
username = 'ammyxh01'
password = 'ammyxh01'
md5 = hashlib.md5(password.encode())  # 创建MD5对象
password_md5 = md5.hexdigest()  # 调用方法hexdigest()加密
# 构造请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
    'Content-Type': 'application/json;charset=UTF-8'
}
# 构造 url
url_base = r'https://cloud.huaxiaerp.com'
url_login = url_base + r'/jshERP-boot/user/login'
# 构造 data
data_login = {"loginName": username, "password": password_md5}
# 发送请求
resp = requests.post(url_login, json=data_login, headers=headers, verify=False)
# 获取响应
token = resp.json()['data']['token']
print(token)
# 构造请求头
headers['X-Access-Token'] = token

# ----------------------上传文件----------------------
# 构造 url
url_upload = url_base + r'/jshERP-boot/systemConfig/upload'
# 构造 files
files = {
    'file': ('1.txt', open(r'1.txt', mode='rb'), 'text/plain'),
    'biz': 'bill'
}
# 构造请求头
headers.pop('Content-Type')
resp = requests.post(url_upload, files=files, headers=headers, verify=False)
print(resp.text)

